===========================
coding please reference:
===========================
apollo\sdk\include\hal\chipdef\apollo\APOLLO_RegisterFile.pdf
(нTO coding reference pdf file server W̷s)

coding аѦ follow SD6 CodingConvention.pdf 
\\rtdomain\fs\CN_Switch\Project\siH]\V0.0.7\02_CodingConvention.pdf

`ǿ~
(1)
int32 apollo_raw_trap_rmaAction_get(rtk_mac_t *pFrame, rtk_action_t* pAction)
                                                         ^^^^^^^^^^^
                                                          rtk_action_t *pAction

(2)
One declaration per line is recommended since it encourages commenting.
Example:
    int level; /* indentation level */
    int size;  /* size of table */
Avoid:
    int foo, fooarray[];


(3)
Use one space on each side of most binary and ternary operators.
    Such as any of these: = + - < > * / % | & ^ <= >= == != ? :
Ex:
a += c + d;
a = (a + b) / (c * d);
      ^ ^  ^ ^  ^ ^   -->space
      
(4)      
No space after unary operators such as unary minusK, etc.
Such as any of these:
    & * ++ -- ~ !
    sizeof typeof alignof __attribute__ defined

Ex:
if(!expr) --> NO SPACE BEFORE expr


(5)
Put one enum maximum symbol, and its suffix is _END

    typedef enum rtk_enable_e
    {
        DISABLED = 0,
        ENABLED,
        RTK_ENABLE_END
    } rtk_enable_t;


(6)
    typedef struct rtk_vlan_vlanInfo_s    
    {
        unsigned int tableSize; 
        vlan_entry_t *entry;
    } rtk_vlan_vlanInfo_t;

typedef union ski_svlan_data_u    
    {
        unsigned int tableSize; 
        ski_svlan_port_t svlanPort;
        ski_svlan_entry_t svlanEn
    } ski_svlan_data_t;

(7)
Put constant in the left if == appears in your statement
E Constant symbol in left side when compare == between constant and one statement
E This is always safe to put constant value in the left side of == sign; Prevent miss one = problem and hard to debug.
    example: if (RT_ERR_OK == ret)

The >, >=, <, <= is not the above concern.


(8)
Our coding style for comments is the C89 "/* ... */" style. 
Don't use C99-style "// ..." comments.
(open compiler option disable C99)


===========================
OSAL access Utility:
===========================
osal_alloc
osal_free
osal_printf

osal_strlen 
osal_strcmp 
osal_strcpy 
osal_strncpy
osal_strcat 
osal_strchr 
osal_memset 
osal_memcpy 
osal_memcmp 



===========================
Register access Utility:
===========================

(normal API)
int32 reg_field_read(uint32  reg,uint32  field,uint32  *pValue)
int32 reg_field_write(uint32  reg,uint32  field,uint32  *pValue)


(array)
int32 reg_array_field_read(uint32  reg,
                           int32   index_1,
                           int32   index_2,
                           uint32  field,
                           uint32  *pValue)

int32 reg_array_field_write(uint32  reg,
                            int32   index_1,
                            int32   index_2,
                            uint32  field,
                            uint32  *pValue)

@array  䤤@index ж, REG_ARRAY_INDEX_NONE
ߤ@
PORT INDEX : index_1 --> port_idx
             index_2 --> REG_ARRAY_INDEX_NONE

ARRAY INDEX: index_1 --> REG_ARRAY_INDEX_NONE
             index_2 --> index               


reg P field аѦ pdf file
reg  :   [REGISTER_NAME]r
field:   [FILED_NAME]f


(******note!!******)
register access 
reg_field_read/reg_array_field_read
reg_field_write/reg_array_field_write




======================================================
Register array access Utility for multiple word register array:
======================================================
(array)
int32 reg_array_read(uint32 reg, 
                     int32 index_1, 
                     int32 index_2, 
                     uint32 *pValue)

int32 reg_array_write(uint32 reg, 
                      int32 index_1, 
                      int32 index_2, 
                      uint32 *pValue)


int32 reg_array_field_read(uint32  reg,
                           int32   index_1,
                           int32   index_2,
                           uint32  field,
                           uint32  *pValue)

int32 reg_array_field_write(uint32  reg,
                            int32   index_1,
                            int32   index_2,
                            uint32  field,
                            uint32  *pValue)


(ĳϥΪk -- Wfield access)
reg_array_field_read/reg_array_field_write



(ĳϥΪk -- hfield access /write multiple field)
uint32 pValue[APOLLO_REGSIZE_WORDLEN];
/*direcr IO access*/
reg_array_read(reg,index_1,index_2,pValue);

/*set field value to RAM buffer pValue*/
reg_field_set(reg,field1,&field_data,pValue);
reg_field_set(reg,field2,&field_data,pValue);
reg_field_set(reg,field3,&field_data,pValue);
...

/*direcr IO access write to ASIC*/
reg_array_write(reg,index_1,index_2,pValue);



(ĳϥΪk -- hfield access /read multiple field)


uint32 pValue[APOLLO_REGSIZE_WORDLEN_MAX];
/*direcr IO access*/
reg_array_read(reg,index_1,index_2,pValue);

/*get field value from RAM buffer pValue*/
reg_field_get(reg,field1,&field_data,pValue);
reg_field_get(reg,field2,&field_data,pValue);
reg_field_get(reg,field3,&field_data,pValue);
...





===========================
Table Access Utility
===========================
[Direct ASIC Access]
int32 table_read(uint32 table,uint32 addr,uint32 *pData)
int32 table_write(uint32 table,uint32 addr,uint32 *pData)

[RAM Buffer Access]
int32 table_field_get(uint32  table,uint32 field,uint32 *pValue,uint32  *pData)
int32 table_field_set(uint32  table,uint32 field,uint32 *pValue,uint32  *pData)

int32 table_field_byte_get(uint32 table,uint32 field,uint8 *pValue,uint32 *pData)
int32 table_field_byte_set(uint32  table,uint32 field,uint8 *pValue,uint32 *pData)

int32 table_field_mac_get(uint32 table,uint32 field,uint8 *pValue,uint32 *pData)
int32 table_field_mac_set(uint32 table,uint32 field,uint8 *pValue,uint32 *pData)

API k
table    [TABLE_NAME]t
field    [TABLE_NAME]_[FILED_NAME]tf


(for table access)
Add table entry define in
apollo\sdk\include\hal\chipdef\allmem.h
Ex:
MEM_ENTRY_DECLARE(vlan_entry_t, 2);
                                ^ 2 x 32 bits



===========================
Error code define
===========================
Common error
apollo\sdk\system\include\common\error.h

Module error
apollo\sdk\include\common\rt_error.h
Module S error code

W[error code ɤ]nW[error string
apollo\sdk\src\common\rt_error.c function "rt_error_numToStr"


RT_ERR_CHIP_NOT_SUPPORTED   --input data type enum wq support
RT_ERR_INPUT                --input value b enum range   
RT_ERR_OUT_OF_RANGE         --input value bXzrange  ex: port number, index ... 
RT_ERR_NULL_POINTER         --input value NULL pointer 


===========================
Data type 
===========================
check
1.apollo\sdk\system\include\common\type.h
2.apollo\sdk\include\common\rt_type.h
3.apollo\sdk\include\dal\apollo\raw\apollo_raw.h

YLAtype, AW[stype,

[s[type rule]
 if(module S) 
    --> if(RTK API iHϥ)
            ---> wbRTK layer  [module].h
        else
            --->  wb apollo_raw_[module].h    
 else
    --> if(D`common)
         ---> wb type.h
        else
         ---> rt_type.h  



              

===========================
Add Data type in apollo_raw_[module].h 
===========================
1.Naming Х apollo_raw_XXX  }Y
2.enum eХ[  RAW_  prefix
3.Data structure  member Х unit32, Kcoding  
4.RAW driver index Щb data structurḙ


===========================
Data type coding in raw driver 
===========================
1.YѼƨϥ RAW driver define type, 
  RAW driver coding iHۤvdefine driver ۦPҥHO_ഫۨMw
  gRTK API ɥ`N

2.YѼƨϥ RTK layer define type,  
  RAW driver ۤvݰn RTK parameter P ASIC define ഫ
  

===========================
Coding style
===========================
Please follow sample code
-reg_access.c
-table_access.c


===========================
How to Make your Driver Code
===========================
Add file in apollo\sdk\src\dal\apollo\raw\apollo_raw_[your_module].c

Edit apollo\internal\apollo\diagShellCygwin\build\Makefile.rtk
Add apollo_raw_[your_module].o
W[۹m

Make your code via Cygwin
Set path to apollo\internal\apollo\diagShellCygwin\
make all

(sget code ɽХ make shell_tree)








===============================
update 2011/09/15
===============================
1. register access Yregister WL 1 word 
   reg_array_field_read / reg_array_field_write  
    
   OIO issue  h reg_array_field_read / reg_array_field_write ѨM
   
   ҥHregister access ٬O, Шϥ
   reg_array_field_read / reg_array_field_write
   
   
2. raw driver Ѽƽкɶqg structure
   ex:
   dal_raw_XXX_miscCounter_get(uint32 *miscCnt1,uint32 *miscCnt2,uint32 *miscCnt3) 
 
   -->
   dal_raw_XXX_miscCounter_get(XXX_MISC_CNT_T *cnts) 
   
3. diag string display

   bA diag_xxx.c file Ah extern array 
    string array ŧifollow HURW覡
    Х  diagStr_  prefix
 
    const char *diagStr_enable[RTK_ENABLE_END] = {
        DIAG_STR_DISABLE,
        DIAG_STR_ENABLE
    };
   

  extern array 
  вΤ@b  
  apollo\sdk\src\app\diag\include\diag_str.h

  extern const char *diagStr_enable[];


4. Function Header аȥTg. 
   Tools |header API document(RTK API only?)
   
    raw driver .h header

5. error check
    HAL_IS_PORT_EXIST(port)  
    
    apollo\sdk\include\hal\common\halctrl.h
    
    ڭ̥Tg
    static rt_register_capacity_t apollo_capacityInfo  
    
    apollo\sdk\src\hal\chipdef\chip.c 
    
    structure define in 
    apollo\sdk\include\hal\chipdef\chip.h
    
    (a)Ysfeature мW[structure e
    (b)æb halctrl.h W[error check macro
    
    
    :
    diag_shell
        J all  ]tCPU port (all u]tethernet port)
        nJ]tCPU port Х 0-6
        
    sdk driver utilty

    #define HAL_IS_PORT_EXIST(port)           RTK_PORTMASK_IS_PORT_SET(hal_ctrl.pDev_info->pPortinfo->all.portmask, port)
      -->]tCPU port  
    #define HAL_IS_ETHER_PORT(port)           RTK_PORTMASK_IS_PORT_SET(hal_ctrl.pDev_info->pPortinfo->ether.portmask, port)                                                         
      -->ut ethernet port                                                                                                                                                                                                        